package com.dems.core.util;

import org.apache.commons.lang3.time.DateFormatUtils;

import java.util.Date;

public class SerialNoUtil {


    /**
     * 生成订单号
     *
     * @return
     */
    public static String generateOrderId() {
        String randThree = String.valueOf(System.nanoTime()).substring(7, 10);
        String date = DateFormatUtils.format(new Date(), "yyyyMMdd");
        String randThreeMiddle = String.valueOf(System.nanoTime()).substring(7, 10);
        String seconds = DateFormatUtils.format(new Date(), "HHmmss");
        String randThreeTail = String.valueOf(System.nanoTime()).substring(7, 10);
        return date + "01" + randThree + "0" + seconds + randThreeTail;
    }


    /**
     * 生成用户编号
     *
     * @return
     */
    public static String generateUserId() {


        return null;
    }


    /**
     * 生成n位验证码
     *
     * @return
     */
    public static String generateCode(int count) {
        return String.valueOf((int) ((Math.random() * 9 + 1) * Math.pow(10, count - 1)));
    }

    /**
     * 生成6位验证码
     *
     * @return
     */
    public static String generateCodeDefault() {
        return generateCode(6);
    }

}
